using System;
using UseCaseManager.BO;

namespace UseCaseManager.Test.BO
{
    public partial class TestUtilsRelease
    {
        /// <summary>
        /// Creates a new saved Release with a random value assigned to every property
        /// </summary>
        public static Release CreateSavedRelease()
        {
            Release release = CreateUnsavedValidRelease();
            release.Save();
            return release;
        }
        /// <summary>
        /// Creates a new saved Release with a random value assigned to every property
        /// </summary>
        public static Release CreateSavedRelease(DateTime startWorkDate, DateTime endWorkDate)
        {
            Release release = CreateUnsavedValidRelease(startWorkDate, endWorkDate);
            release.Save();
            return release;
        }

        /// <summary>
        /// Creates a new unsaved Release with a random value assigned to every property
        /// </summary>
        public static Release CreateUnsavedValidRelease()
        {
            return CreateUnsavedValidRelease(TestUtils.GetRandomDate(), TestUtils.GetRandomDate());
        }
        /// <summary>
        /// Creates a new unsaved Release with a random value assigned to every property
        /// </summary>
        public static Release CreateUnsavedValidRelease(DateTime startWorkDate, DateTime endWorkDate)
        {
            Release release = new Release();
            release.StartWorkDate = startWorkDate;
            release.ProjectID = Guid.NewGuid();
            release.EndWorkDate = endWorkDate;
            release.ReleaseName = TestUtils.GetRandomString();
            return release;
        }

        /// <summary>
        /// Creates a new unsaved Release where all properties are null, except ID properties
        /// and those with default values.  If there are compulsory properties without
        /// defaults, saving the object will throw an exception.
        /// </summary>
        public static Release CreateUnsavedDefaultRelease()
        {
            Release release = new Release();
            return release;
        }

        /// <summary>
        /// Creates a saved hierarchy of a Release, Drops and Use Cases. PointsAssigned is set on each Use Case.
        /// </summary>
        public static Release CreateRelease2Drops_FirstDrop_3UseCases_SecondDrop_2UseCases(out Drop drop, out Drop drop2)
        {
            Release release = CreateSavedRelease();
            int expectePointsAssignedDrop;
            const int expectedNumberOfUseCasesDrop = 3;
            drop = TestUtilsDrop.CreateSavedDrop_WUseCases(release, expectedNumberOfUseCasesDrop, out expectePointsAssignedDrop);
            int expectedPointsAssignedDrop2;
            const int expectedNumberOfUseCasesDrop2 = 2;
            drop2 = TestUtilsDrop.CreateSavedDrop_WUseCases(release, expectedNumberOfUseCasesDrop2, out expectedPointsAssignedDrop2);
            drop.Name = "Drop1 Name";
            drop2.Name = "Drop2 Name";
            drop.Save();
            drop2.Save();
            release.Save();
            return release;
        }

        /// <summary>
        /// Creates an unsaved hierarchy of a Release, Drops and Use Cases. PointsAssigned is set on each Use Case.
        /// 
        /// </summary>
        public static Release CreateUnsavedRelease2DropsOrderdByEndDate(out Drop drop, out Drop drop2)
        {
            Release release = CreateUnsavedValidRelease();
            drop = TestUtilsDrop.CreateUnsavedDrop_WUseCases(3);
            drop2 = TestUtilsDrop.CreateUnsavedDrop_WUseCases(5);

            drop.Name = "Drop1 Name";
            drop.EndDate = DateTime.Now.AddDays(1);
            drop2.Name = "Drop2 Name";
            drop2.EndDate = DateTime.Now.AddDays(8);
            release.Drops.Add(drop);
            release.Drops.Add(drop2);
            return release;
        }

        public static Release CreateUnsavedRelease3DropsOrderdByEndDate(out Drop drop1, out Drop drop2, out Drop drop3)
        {
            Release release = CreateUnsavedValidRelease();
            drop1 = TestUtilsDrop.CreateUnsavedDrop_WUseCases(3);
            drop2 = TestUtilsDrop.CreateUnsavedDrop_WUseCases(5);
            drop3 = TestUtilsDrop.CreateUnsavedDrop_WUseCases(9);

            drop1.Name = "Drop1 Name";
            drop1.EndDate = DateTime.Now.AddDays(1);
            drop2.Name = "Drop2 Name";
            drop2.EndDate = DateTime.Now.AddDays(8);
            drop3.EndDate = drop2.EndDate.Value.AddDays(7);
            release.Drops.Add(drop1);
            release.Drops.Add(drop2);
            release.Drops.Add(drop3);
            return release;
        }

        public static Release CreateUnsavedRelease_3Drops_OrderedByEndDate()
        {
            Release release = CreateUnsavedValidRelease();
            Drop drop1 = TestUtilsDrop.CreateUnsavedDrop_WUseCases(3);
            Drop drop2 = TestUtilsDrop.CreateUnsavedDrop_WUseCases(5);
            Drop drop3 = TestUtilsDrop.CreateUnsavedDrop_WUseCases(9);

            drop1.Name = "Drop1 Name";
            drop1.EndDate = DateTime.Now.AddDays(1);
            drop2.Name = "Drop2 Name";
            drop2.EndDate = DateTime.Now.AddDays(8);
            drop3.EndDate = drop2.EndDate.Value.AddDays(7);
            release.Drops.Add(drop1);
            release.Drops.Add(drop2);
            release.Drops.Add(drop3);
            return release;
        }
    }
}